
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>API 和 ABI 版本管理 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="分发 Python 模块" href="../distributing/index.html" />
    <link rel="prev" title="使对象类型支持循环垃圾回收" href="gcsupport.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/c-api/apiabiversion.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="../distributing/index.html" title="分发 Python 模块"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="gcsupport.html" title="使对象类型支持循环垃圾回收"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python/C API 参考手册</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="api-and-abi-versioning">
<span id="apiabiversion"></span><h1>API 和 ABI 版本管理<a class="headerlink" href="#api-and-abi-versioning" title="永久链接至标题">¶</a></h1>
<p><code class="docutils literal notranslate"><span class="pre">PY_VERSION_HEX</span></code> 是Python的版本号的单一整数形式。</p>
<p>例如, 如果 &quot;PY _ VERSION _ HEX&quot; 设置为 &quot;0x0304012&quot;, 则可以通过按以下方式将其视为32位数字来查找基础版本信息:</p>
<blockquote>
<div><table class="docutils align-default">
<colgroup>
<col style="width: 9%" />
<col style="width: 31%" />
<col style="width: 60%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>字节串</p></th>
<th class="head"><p>位数（大端字节序）</p></th>
<th class="head"><p>含义</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">1</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">1-8</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">PY_MAJOR_VERSION</span></code> (the <code class="docutils literal notranslate"><span class="pre">3</span></code> in
<code class="docutils literal notranslate"><span class="pre">3.4.1a2</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">2</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">9-16</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">PY_MINOR_VERSION</span></code> (the <code class="docutils literal notranslate"><span class="pre">4</span></code> in
<code class="docutils literal notranslate"><span class="pre">3.4.1a2</span></code>)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">3</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">17-24</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">PY_MICRO_VERSION</span></code> (the <code class="docutils literal notranslate"><span class="pre">1</span></code> in
<code class="docutils literal notranslate"><span class="pre">3.4.1a2</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">4</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">25-28</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">PY_RELEASE_LEVEL</span></code> (<code class="docutils literal notranslate"><span class="pre">0xA</span></code> 是 alpha版本, <code class="docutils literal notranslate"><span class="pre">0xB</span></code> 是 beta版本, <code class="docutils literal notranslate"><span class="pre">0xC</span></code> 发布的候选版本并且 <code class="docutils literal notranslate"><span class="pre">0xF</span></code> 是最终版本)，在这个例子中这个版本是alpha版本。</p></td>
</tr>
<tr class="row-even"><td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">29-32</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">PY_RELEASE_SERIAL</span></code> (<code class="docutils literal notranslate"><span class="pre">3.4.1a2``中的``2</span></code>，最终版本用0)</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>因此 <code class="docutils literal notranslate"><span class="pre">3.4.1a2</span></code> 的16进制版本号是 <code class="docutils literal notranslate"><span class="pre">0x030401a2</span></code> 。</p>
<p>所有提到的宏都定义在 <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Include/patchlevel.h">Include/patchlevel.h</a>。</p>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="gcsupport.html"
                        title="上一章">使对象类型支持循环垃圾回收</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="../distributing/index.html"
                        title="下一章">分发 Python 模块</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/c-api/apiabiversion.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="../distributing/index.html" title="分发 Python 模块"
             >下一页</a> |</li>
        <li class="right" >
          <a href="gcsupport.html" title="使对象类型支持循环垃圾回收"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>